import django_filters
from .models import Comment, CommentReport


class CommentFilter(django_filters.FilterSet):
    book = django_filters.NumberFilter(field_name='book__id')
    user = django_filters.NumberFilter(field_name='user__id')
    rating = django_filters.NumberFilter(field_name='rating')
    min_rating = django_filters.NumberFilter(field_name='rating', lookup_expr='gte')
    max_rating = django_filters.NumberFilter(field_name='rating', lookup_expr='lte')
    is_approved = django_filters.BooleanFilter()
    is_verified = django_filters.BooleanFilter()
    start_date = django_filters.DateFilter(field_name='created_at', lookup_expr='gte')
    end_date = django_filters.DateFilter(field_name='created_at', lookup_expr='lte')
    
    class Meta:
        model = Comment
        fields = ['book', 'user', 'rating', 'is_approved', 'is_verified', 
                 'start_date', 'end_date']


class CommentReportFilter(django_filters.FilterSet):
    comment = django_filters.NumberFilter(field_name='comment__id')
    reporter = django_filters.NumberFilter(field_name='reporter__id')
    status = django_filters.ChoiceFilter(choices=CommentReport.STATUS_CHOICES)
    reason = django_filters.ChoiceFilter(choices=CommentReport.REASON_CHOICES)
    start_date = django_filters.DateFilter(field_name='created_at', lookup_expr='gte')
    end_date = django_filters.DateFilter(field_name='created_at', lookup_expr='lte')
    
    class Meta:
        model = CommentReport
        fields = ['comment', 'reporter', 'status', 'reason', 
                 'start_date', 'end_date']
